package beans {
	import mx.collections.ArrayCollection;
	
	public class CompanyBean {

		//------------------------------------------------------------
		//
		// variables
		//
		//------------------------------------------------------------
	
		//------------------------------
		// roomID
		//------------------------------

		private var _roomID:uint;

		public function get roomID():uint {
			return _roomID;
		}

		public function set roomID(roomID:uint):void {
			_roomID = roomID;
		}

		//------------------------------
		// requested rooms id
		//------------------------------

		private var _requestRoomList:ArrayCollection;

		public function get requestRoomList():ArrayCollection {
			return _requestRoomList;
		}

		public function set requestRoomList(requestRoomList:ArrayCollection):void {
			_requestRoomList = requestRoomList;
		}

		//------------------------------
		// companyID
		//------------------------------

		private var _companyID:uint;

		public function get companyID():uint {
			return _companyID;
		}

		public function set companyID(companyID:uint):void {
			_companyID = companyID;
		}
		
	
		//------------------------------
		// companyName
		//------------------------------

		private var _companyName:String;

		public function get companyName():String {
			return _companyName;
		}

		public function set companyName(companyName:String):void {
			_companyName = companyName;
		}
	
		//------------------------------
		// contact
		//------------------------------

		private var _contact:String;

		public function get contact():String {
			return _contact;
		}

		public function set contact(contact:String):void {
			_contact = contact;
		}
	
		//------------------------------
		// tel
		//------------------------------

		private var _tel:String;

		public function get tel():String {
			return _tel;
		}

		public function set tel(tel:String):void {
			_tel = tel;
		}
	
		//------------------------------
		// description
		//------------------------------

		private var _description:String;

		public function get description():String {
			return _description;
		}

		public function set description(description:String):void {
			_description = description;
		}
	
		//------------------------------
		// hireInfoList
		//------------------------------

		private var _hireInfoList:ArrayCollection;

		public function get hireInfoList():ArrayCollection {
			return _hireInfoList;
		}

		public function set hireInfoList(hireInfoList:ArrayCollection):void {
			_hireInfoList = hireInfoList;
		}
	
		//------------------------------------------------------------
		//
		// constructor
		//
		//------------------------------------------------------------
		
		public function CompanyBean(value:XML) {
			if (!value) {
				companyName = "";
				contact = "";
				tel = "";
				description = "";
				hireInfoList = new ArrayCollection();
				requestRoomList = new ArrayCollection();
				return;
			}
			
			roomID = value.roomID;
			companyID = value.comid;
			companyName = value.companyName;
			contact = value.contact;
			tel = value.tel;
			description = value.description;
			
			hireInfoList = new ArrayCollection();
			for each(var hireInfo:XML in value.hireInfoList.hireInfo) {
				hireInfoList.addItem( new HireBean(hireInfo) );
			}
			
			requestRoomList = new ArrayCollection();
			for each(var rid:int in value.hireInfoList.requestRoomList) {
				requestRoomList.addItem(rid);
			}
		}
		
		//------------------------------------------------------------
		//
		// methods
		//
		//------------------------------------------------------------
		
		/**
		 * return a clone object
		 */
		public function clone():CompanyBean {
			return new CompanyBean( XML(XML(this.toXMLString()).data) );
		}
		
		/**
		 * represent this object as a xml object
		 * @return the string format of the xml object
		 */
		public function toXMLString():String {
			var rootNode:XML = <results/>;
			
			var dataNode:XML = <data/>;
			rootNode.appendChild(dataNode);
			
			var roomIDNode:XML = <roomID>{roomID}</roomID>;
			dataNode.appendChild(roomIDNode);
			
			var companyIDNode:XML = <companyID>{companyID}</companyID>;
			dataNode.appendChild(companyIDNode);

			var companyNameNode:XML = <companyName>{companyName}</companyName>;
			dataNode.appendChild(companyNameNode);
			
			var contactNode:XML = <contact>{contact}</contact>;
			dataNode.appendChild(contactNode);
			
			var telNode:XML = <tel>{tel}</tel>;
			dataNode.appendChild(telNode);
			
			var descriptionNode:XML = <description>{description}</description>;
			dataNode.appendChild(descriptionNode);
			
			var hireInfoListNode:XML = <hireInfoList/>;
			for each (var hireInfo:HireBean in hireInfoList) {
				hireInfoListNode.appendChild(hireInfo.toXML());
			}
			dataNode.appendChild(hireInfoListNode);
			
			var requestRoomListXML:XML = <requestRoomList/>
			for each (var rid:int in requestRoomList) {
				requestRoomListXML.appendChild(<roomID>{rid}</roomID>);
			}
			dataNode.appendChild(requestRoomListXML);
			
			return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + rootNode.toXMLString();
		}

	}
}